package cn.xshi.bpm.web;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import cn.xshi.bpm.param.NodeAttributeParam;
import cn.xshi.bpm.service.LcNodeAttributeService;
import cn.xshi.bpm.service.LcNodeBtnService;
import io.swagger.annotations.Api;
import cn.xshi.common.annotation.Auth;
import cn.xshi.common.base.BasePage;
import cn.xshi.common.base.BaseResult;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.util.ExceptionUtil;
import cn.xshi.bpm.model.LcNodeBtn;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import cn.xshi.common.util.StringUtil;
import io.swagger.annotations.ApiOperation;
import com.github.pagehelper.PageInfo;
import cn.xshi.common.base.BaseSearch;
import cn.xshi.bpm.model.LcNodeAttribute;

import javax.annotation.Resource;
/**
* @Desc 节点属性 
* @Author 邓纯杰
* @CreateTime 2022-03-27 22:05:30
*/
@Api(value = "节点属性",description = "节点属性", tags = "节点属性")
@RestController
@RequestMapping("/lcNodeAttribute")
public class LcNodeAttributeController extends BaseAction {

	@Resource
	private LcNodeAttributeService lcNodeAttributeService;

	@Resource
	private LcNodeBtnService lcNodeBtnService;

	/**
	* 查询并分页
	* @param baseSearch 
	*/
	@ApiOperation(value="查询并分页", notes="查询并分页")
	@PostMapping(value="/list")
	@Auth(value = "/lcNodeAttribute/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BasePage<List<LcNodeAttribute>> getLcNodeAttributeListByCondition(@RequestBody(required=true)BaseSearch baseSearch){
		Map<String, Object> condition = baseSearch.convert();
		commonHPager(baseSearch);
		List<LcNodeAttribute> lcNodeAttributeList = lcNodeAttributeService.getLcNodeAttributeListByCondition(condition);
		PageInfo<LcNodeAttribute> page = new PageInfo<LcNodeAttribute>(lcNodeAttributeList);
		return outPageBootStr(page,baseSearch);
	}

	/**
	* 查询单条记录
	* @param id
	*/
	@ApiOperation(value="查询单条记录", notes="查询单条记录")
	@GetMapping(value="/get/{id}")
	@Auth(value = "/lcNodeAttribute/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BaseResult<LcNodeAttribute> getLcNodeAttributeById(@PathVariable("id")String id){
		LcNodeAttribute lcNodeAttribute = lcNodeAttributeService.getLcNodeAttributeById(id);
		if(null != lcNodeAttribute){
			Map<String,Object> condition = new HashMap<>();
			condition.put("lcNodeAttributeId",lcNodeAttribute.getId());
			List<LcNodeBtn> lcNodeBtns = lcNodeBtnService.getLcNodeBtnListByCondition(condition);
			lcNodeAttribute.setLcNodeBtns(lcNodeBtns);
		}
		return outDataStr(lcNodeAttribute);
	}

	/**
	 * 保存
	 * @param lcNodeAttribute
	 */
	@ApiOperation(value="保存", notes="保存")
	@PostMapping(value="/save")
	public BaseResult saveLcNodeAttribute(@RequestBody LcNodeAttribute lcNodeAttribute){
		int i = 0;
		if(null != lcNodeAttribute){
			i=lcNodeAttributeService.saveLcNodeAttribute(lcNodeAttribute);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	* 删除
	* @param id
	*/
	@ApiOperation(value="删除", notes="删除")
	@DeleteMapping(value="/delete")
	public BaseResult delLcNodeAttribute(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i=lcNodeAttributeService.delLcNodeAttribute(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 *
	 * @param nodeAttributeParam
	 * @return
	 */
	@ApiOperation(value="查询单条记录", notes="查询单条记录")
	@Auth(value = "/lcNodeAttribute/attribute",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@GetMapping(value="/attribute")
	public BaseResult<LcNodeAttribute> getLcNodeAttribute(NodeAttributeParam nodeAttributeParam){
		if(StringUtil.isEmpty(nodeAttributeParam.getNodeId())){
			throw new ExceptionUtil("节点编号为空");
		}
		if(StringUtil.isEmpty(nodeAttributeParam.getHid_()) && StringUtil.isEmpty(nodeAttributeParam.getMountsId())){
			throw new ExceptionUtil("挂载编号和历史版本号为空");
		}
		LcNodeAttribute lcNodeAttribute = lcNodeAttributeService.getLcNodeAttribute(nodeAttributeParam);
		return outDataStr(lcNodeAttribute);
	}

}
